package com.holiday.mybatis;

import com.holiday.mybatis.dao.VideoMapper;
import com.holiday.mybatis.dao.VideoOrderMapper;
import com.holiday.mybatis.domain.User;
import com.holiday.mybatis.domain.Video;
import com.holiday.mybatis.domain.VideoOrder;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * 事务管理
 *      1、在mybatis-config.xml配置
 *          1、<transactionManager type="JDBC"/> ：配置成JDBC，事务交给Springboot管理
 *          2、<transactionManager type="MANAGED"/>：配置成MANAGED，需要代码提交管理
 */
import java.io.InputStream;
import java.util.*;

public class SqlSessionApp {
    public static void main(String[] args) throws Exception {
        String resource = "config/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        VideoMapper videoMapper = sqlSession.getMapper(VideoMapper.class);
        VideoOrderMapper  videoOrderMapper = sqlSession.getMapper(VideoOrderMapper.class);

        Video video = new Video();
        video.setTitle("holiday");
        video.setCoverImg("xxx");
        video.setPoint(9.7);
        video.setCreateTime(new Date());
        video.setPrice(9900);
        video.setSummary("xxxa");

        Video video1 = new Video();
        video1.setTitle("holiday54");
        video1.setId(53);
        video1.setCoverImg("xxx");
        video1.setPoint(9.7);
        video1.setCreateTime(new Date());
        video1.setPrice(9900);
        video1.setSummary("xxxa");

        Map<String,Object> map = new HashMap<>();
        map.put("createTime","2021-01-11 09:33:20");
        map.put("price",9000);

        List<VideoOrder> videoOrders = videoOrderMapper.queryVideoOrderListLazy();

        for(VideoOrder videoOrder:videoOrders){
            System.out.println(videoOrder);
        }


    }
}
